/*
 * dTranslateIface.cpp
 *
 *  Created on: 16.08.2009
 *      Author: index01d
 */

#include "dTranslateIface.h"

dTranslateIface::dTranslateIface(int& argc, char** argv)
								: QApplication(argc,argv)
{
	//Initialization
    w = new dtranslator();  //Input Widget
    l = new langsDialog();  //Language dialog
    tray = new dTrayIcon(); //Tray Icon
    gTr = new gTranslate(); //Translate object
    trayMenu = new QMenu("dTranslate");
    l->setLangs(gTr->getLangs()); //Fills languages

    //Tray menu set

    trayMenu->addAction("Select Language");
    //trayMenu->addAction("About");
    trayMenu->addAction("Quit");
    tray->setContextMenu(trayMenu);

    //Icon set
    QIcon tIcon(applicationDirPath()+"/Dictionary_64.png");
    setWindowIcon(tIcon);
    tray->setIcon(tIcon);

    //Events Set
    connect(trayMenu,SIGNAL(triggered(QAction *)), //Menu click
    		this,SLOT(trayAction(QAction *)));
    connect(w,SIGNAL(getTranslate(QString)), //Need translate
    		gTr,SLOT(translateString(QString)));
    connect(gTr,SIGNAL(tReady(QString)),w,SLOT(tReady(QString))); //Translate ready
    connect(tray,SIGNAL(activated(QSystemTrayIcon::ActivationReason)), //Tray click
    		w,SLOT(needShow(QSystemTrayIcon::ActivationReason)));
    connect(l,SIGNAL(langChanged(const QString&, const QString&)), //Languages was changed
    		gTr,SLOT(setLangs(const QString&,const QString)));
    //
    tray->show();
}

dTranslateIface::~dTranslateIface()
{
	delete w;
	delete l;
	delete tray;
	delete gTr;
	delete trayMenu;
}

void dTranslateIface::trayAction(QAction* action)
{
	if(action->text()=="Quit")
		emit(quit());
	if(action->text()=="Select Language")
		l->show();
	if(action->text()=="About")
		showAbout();
}

void dTranslateIface::showAbout()
{

}
